﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.IO;
using System.Drawing;

public partial class ybqy_print_t3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection sqlcon = new SqlConnection();
        sqlcon.ConnectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
        sqlcon.Open();

        SqlCommand sqlcmd = new SqlCommand("select map_name3 from F_FACTMAP where ShenBaoNianDu='" + Session["ShenBaoNianDu"] + "' and qiyeid=" + Session["qiyeid"], sqlcon);

        SqlDataReader reader = sqlcmd.ExecuteReader(CommandBehavior.CloseConnection);



        if (!IsPostBack)
        {
            if (reader.Read())
            {
                if (reader["map_name3"].ToString() == null || reader["map_name3"].ToString() == "")
                {
                    sqlcon.Close(); return;
                }
                string fileName = reader["map_name3"].ToString();
                Image1.ImageUrl = "~/fileUpload/" + fileName;
                string path = Server.MapPath("~/fileUpload/");
                string sourcePath = path;
                if (!Directory.Exists(path))
                {  //判断是否存在uploadfile路径                     Directory.CreateDirectory(path);                 } 
                    //if (!Directory.Exists(sourcePath))    //判断 、创建原图片路径                 { 
                    //    Directory.CreateDirectory(sourcePath);
                }
                //上传原图片 

                Bitmap oldbitmap = new Bitmap(sourcePath + fileName);
                int Height = oldbitmap.Height;
                int Width = oldbitmap.Width;
                Image1.Height = 400;
                Image1.Width = 700;

                int nwidth = 400 * Width / Height;
                if (nwidth > 700)
                {
                    Image1.Height = 700 * Height / Width;
                }
                else
                {
                    Image1.Width = 400 * Width / Height;
                }

                oldbitmap.Dispose();
            }

            sqlcon.Close();

        }

    }
}